# coding=utf8
'''
Created on 2017年11月9日

@author: shuiting
'''
import urllib2
import time
def tou():
    url = 'http://sl9uk9.v.vote8.cn/m/Shortcut/6887388'
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36 OPR/48.0.2685.52",
        "Content-Type": "application/x-www-form-urlencoded"
    }
    source_data = "__EVENTTARGET=ctl00%24content%24lbtnVote&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUKMTk3MTgyNzcwNmRkytzSaPArrXXfDVFcOMwgj2ozC%2Fs%3D&__VIEWSTATEGENERATOR=C9E13C34&ctl00%24content%24hiddenWeixinUserInfoJson=&ctl00%24content%24hiddenWeixinUserInfoJsonEncode=&ctl00%24content%24ucComment%24hiddenWeixinNickname=&ctl00%24content%24ucComment%24hiddenWeixinHeadImgUrl=&ctl00%24content%24ucComment%24hiddenWeixinHeadImgSmallUrl=&ctl00%24content%24ucComment%24tbNickname=&ctl00%24content%24hiddenRefererUrl=http%3A%2F%2Fsl9uk9.v.vote8.cn%2Fm%2FDescription%2F6887388&ctl00%24content%24hiddenTimeStampEncodeString=1510136839%2C1dd18b51c156cf0eb901d0a67f7ee3b4&ctl00%24content%24hiddenLatitude=&ctl00%24content%24hiddenLongitude=&ctl00%24content%24hiddenGeoLocationEncode=&ctl00%24content%24hiddenVoteChannel=MobileWeb"

    line=open("proxy.txt", "r")
    try:
        for proxy in line:
            ip=eval(proxy)
            httpproxy_handler = urllib2.ProxyHandler(ip)
            nullproxy_handler = urllib2.ProxyHandler({})
            if True:
                opener = urllib2.build_opener(httpproxy_handler)
            else:
                opener = urllib2.build_opener(nullproxy_handler)
            count = 0
            urllib2.install_opener(opener)
            while count < 3:
                req = urllib2.Request(url, data=source_data, headers=headers)
                response=urllib2.urlopen(req).read()
                with open("result.txt", "a+") as f:
                    f.write(response)
                time.sleep(5)
                count+=1
    finally:
        line.close()



if __name__ == '__main__':
    tou()